<template>
  <div v-if="visible" class="delete-confirm-overlay">
    <div class="delete-confirm-modal">
      <h3>确认删除</h3>
      <p>您确定要删除此项吗？此操作不可撤销。</p>
      <div class="actions">
        <button class="cancel-button" @click="handleCancel">取消</button>
        <button class="confirm-button" @click="handleConfirm">确认删除</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

// 定义 props
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
});

// 定义 emits
const emit = defineEmits(['update:visible', 'confirm', 'cancel']);

// 处理确认删除
const handleConfirm = () => {
  emit('confirm'); // 触发确认事件
  emit('update:visible', false); // 关闭弹窗
};

// 处理取消
const handleCancel = () => {
  emit('cancel'); // 触发取消事件
  emit('update:visible', false); // 关闭弹窗
};
</script>

<style scoped>
/* 遮罩层样式 */
.delete-confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000; /* 确保在最上层 */
}

/* 弹窗样式 */
.delete-confirm-modal {
  background-color: #ffffff;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.delete-confirm-modal h3 {
  margin: 0 0 10px;
  font-size: 20px;
  color: #333;
}

.delete-confirm-modal p {
  margin: 0 0 20px;
  font-size: 16px;
  color: #666;
}

/* 按钮容器样式 */
.actions {
  display: flex;
  justify-content: center;
  gap: 20px;
}

/* 取消按钮样式 */
.cancel-button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background-color: #f0f0f0;
  color: #333;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.cancel-button:hover {
  background-color: #e0e0e0;
}

/* 确认按钮样式 */
.confirm-button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background-color: #ff4500;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.confirm-button:hover {
  background-color: #e63900;
}
</style>